//
//  ST_GiveGiftForChatCell.swift
//  btvideo
//
//  Created by mac on 2020/7/3.
//  Copyright © 2020 JarvanZhang. All rights reserved.
//

import UIKit
import SwifterSwift

class ST_GiveGiftForChatCell: UICollectionViewCell {
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        self.contentView.addSubview(border_sup_view)
        border_sup_view.snp.makeConstraints { (make) in
            make.edges.equalToSuperview()
        }
        
        self.contentView.addSubview(cover_image_view)
        cover_image_view.snp.makeConstraints { (make) in
            make.edges.equalToSuperview().inset(UIEdgeInsets.init(top: 5, left: 10, bottom: 41, right: 10))
        }
        
     
        self.contentView.addSubview(titleLabel)
        titleLabel.snp.makeConstraints { (make) in
            make.left.right.centerX.equalToSuperview()
            make.top.equalTo(cover_image_view.snp.bottom).offset(5)
            make.height.equalTo(17)
        }
        
        self.contentView.addSubview(content_label)
        content_label.snp.makeConstraints { (make) in
            make.left.right.centerX.equalToSuperview()
            make.top.equalTo(titleLabel.snp.bottom)
            make.height.equalTo(14)
        }
        
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    //    MARK: - Properties
    fileprivate lazy var normal_border_color = UIColor.init(hex: 0xF2F4F7)!
    fileprivate lazy var selected_border_color = UIColor.init(hex: 0xFEC207)!
    
    fileprivate lazy var border_sup_view:UIView = {
       let control = UIView()
        control.cornerRadius = 10
        control.borderColor = normal_border_color
        control.borderWidth = 1
        return control
    }()
    
      fileprivate lazy var cover_image_view:UIImageView = {
         let control = UIImageView()
          control.contentMode = .scaleAspectFill
            control.clipsToBounds = true
          return control
      }()
    
    fileprivate lazy var titleLabel:UILabel = {
        let control = UILabel.init()
        control.text = ""
        control.textColor = Color.init(hexString: "#333333")
        control.textAlignment = .center
        control.font = UIFont.systemFont(ofSize: 12, weight: UIFont.Weight.regular)
        return control
    }()
    
    fileprivate lazy var content_label:UILabel = {
        let control = UILabel.init()
        control.text = ""
        control.textColor = Color.init(hexString: "#ACB4C0")
        control.textAlignment = .center
        control.font = UIFont.systemFont(ofSize: 10, weight: UIFont.Weight.regular)
        return control
    }()
    
//    MARK: - Bind Model
    var model:ST_BTGiftModel?{
        didSet{
            
            guard let m = model else{return}
            
            cover_image_view.pin_setImage(from: m.imageUrl.url, placeholderImage: ST_SwiftConst.shared.fetch_random_place_holder_image())
            
            titleLabel.text = m.title
            
            content_label.text = m.content
            
            border_sup_view.borderColor = m.isSelected ? self.selected_border_color : self.normal_border_color
            
        }
    }
}
